<template>
  <div>
    <h3>父组件</h3>
    <hr />
    <child1 :count="count" />
    <child2 />
  </div>
</template>

<script>
import child1 from '@/components/child/child1.vue'
import child2 from '@/components/child/child2.vue'

export default {
  components: {
    child1,
    child2
  },
  data() {
    return {
      count: 100
    }
  },
  created() {
    // console.log('app')
    // 发布和订阅模式，一定要先订阅后发布
    // this.$eventBus.on('test', () => {
    //   console.log(111)
    // })
    this.$eventBus.on('addCount', (n) => {
      // console.log(n)
      this.count += n
    })
  },
  beforeUnmount() {
    // this.$eventBus.off('test')
    this.$eventBus.off('addCount')
  },
  methods: {}
}
</script>

<style lang="scss" scoped></style>
